package spikes.sideFrame;

import javax.swing.JComponent;

@SuppressWarnings("serial")
public class NarwhalFrame extends JComponent {

	private NarwhalSideButton active;
	private NarwhalInfoScreen info;
	private final int EXPAND = -1;
	private final int COLLAPSE = 1;
	private final int DO_NOTHING = 0;
	private int toDo = 0;

	public NarwhalFrame() {
		setLayout(null);
		
		info = new NarwhalInfoScreen(this);
		info.setBounds(220, 10, 500, 20);
		add(info);

		for (int i = 0; i < 10; i++) {
			NarwhalSideButton b = new NarwhalSideButton(this,i);
			b.setBounds(10, 40 * i + 10, 200, 20);
			add(b);
		}

		Logotype logo = new Logotype();
		logo.setBounds(500, 200, 500, 500);
		add(logo);
	}
	
	public void trigger() {
		if (toDo == DO_NOTHING)
			return;
		if (toDo == COLLAPSE)
			info.collapse();
		else
			info.expand();
		toDo = DO_NOTHING;
	}

	public void setActive(NarwhalSideButton b) {
		if (!info.isEnabled())
			return;
		if (b == active) {
			info.collapse();
			b.setActive(false);
			active = null;
			return;
		}
		toDo = EXPAND;
		info.collapse();
		if (active != null)
			active.setActive(false);
		b.setActive(true);
		active = b;
	}

}
